/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.informet.ipd.modelo.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author LAPTOP01
 */
public class DQuery extends DBase {

    Connection cn = null;

    public DQuery() {
        super();
    }

 public List consulta() { // Ejecuta Select
        List<String[]> regs = new ArrayList<String[]>();
        try {

            ResultSet rs = null;

            ResultSetMetaData rm=null;
            Statement st=null;
            if (cn == null) {
                regs = null;
            } else {
                st = cn.createStatement();
                rs = st.executeQuery("select o.descripcion as [Objetivo estrategico] ,m.descripcion as  [meta] ,m.tipo as [meta tipo],m.cantidad as [meta cantidad] , i.descripcion as indicador,mv.descripcion as medioVer from " +
                        "objestr as o  inner join meta  as m " +
                        "on o.idobes=m.idObEs" +
                        "inner join indicador i " +
                        "on i.idMeta=m.idMeta" +
                        "inner join medioVer mv" +
                        "on i.idIndicador=mv.idIndicador");
                 rm = rs.getMetaData();
                int numCols = rm.getColumnCount();

                // Toma los tÃ­tulos de las columnas
                String[] titCols = new String[numCols];
                for (int i = 0; i < numCols; ++i) {
                    titCols[i] = rm.getColumnName(i + 1);
                }
                // la fila 0 del vector lleva los tÃ­tulos de las columnas
                regs.add(titCols);
                // toma las filas de la consulta

                while (rs.next()) {
                    String[] reg = new String[numCols];

                    for (int i = 0; i < numCols; i++) {
                        reg[i] = rs.getString(i + 1);
                    }
                    regs.add(reg);
                }
                cn.close();
            }

        } catch (SQLException e) {
            regs = null;
        } catch (Exception e) {
            regs = null;
        }
        return regs;    // returna null si fallÃ³
    }
}
